//监听下载app
$('.idownload-btn').on('click', function() {
  _hmt.push(['_trackEvent', 'shuo_ming_shu', 'click', '0']);
});

//监听许愿
$('.wish-sure').on('click', function() {
  _hmt.push(['_trackEvent', 'wish', 'click', '0']);
});

//监听布拉
$('.bula').on('click', function() {
  _hmt.push(['_trackEvent', 'bula', 'click', '0']);
});

//监听e代泊
$('.bula').on('click', function() {
  _hmt.push(['_trackEvent', 'daibo', 'click', '0']);
});

//监听奇鱼
$('.bula').on('click', function() {
  _hmt.push(['_trackEvent', 'qiyu', 'click', '0']);
});

$(function () {
  $('.info-hide').animate({top:'0vw'},3000);

  //用户信息
  var name1=sessionStorage.getItem('name1');
  var name2=sessionStorage.getItem('name2');
  var num1 = sessionStorage.getItem('num');
  $('.name1').text(name1);
  $('.name2').text(name2);
  $('.num1').text(num1);

  //上传愿望
  $('.wish-sure').on('click',function () {
    var wish = $('.ipt-wish').val();
    if(wish){
      $.ajax({
        type : 'post',
        url : 'wish',
        data : {
          wish:wish
        },
        dataType : 'json',
        success : function(data){
          console.log(data);
          $('.ipt-wish-box').hide();
          var list = '<li index='+data.id+'><p class="user-wish">'+wish+'</p><button type="button" class="zan-btn-box"><img src="../images/xmas/zan.png" alt="" class="zan-btn"></button><span class="count">0</span></li>'
          $('.wish-list').prepend(list);
        }
      })
    }else{
      alert('请输入愿望');
    }
  })

  //增加点赞数
  $('.wish-list').on('click','.zan-btn-box',function () {
    var btn = $(this);
    var wish = $(this).siblings('p').text();
    var count = $(this).siblings('span').text();
    var id = $(this).parent().attr('index');
    console.log(count);
    count++;
    $.ajax({
      type : 'post',
      url : 'praise',
      data : {
        wish:wish,
        count:count,
        id:id
      },
      dataType : 'json',
      success : function(data){
        console.log(data);
        btn.find('img').attr('src','../images/xmas/no_zan.png');
        btn.attr('disabled','disabled');
        btn.siblings('span').text(count);
      }
    })
  })

  //查看更多愿望
  $('.check-more').on('click',function () {
    var id = $('.wish-list li:last').attr('index');
    if(id == 1){
      alert('没有更多愿望');
    }else{
      $.ajax({
        type : 'post',
        url : 'more',
        data : {
          id:id,
        },
        dataType : 'json',
        success : function(data){
          var wish = data.wish;
          for(var i = 0;i<wish.length;i++){
            var list = '<li index='+wish[i].id+'><p class="user-wish">'+wish[i].wish+'</p><button type="button" class="zan-btn-box"><img src="../images/xmas/zan.png" alt="" class="zan-btn"></button><span class="count">'+wish[i].praise+'</span></li>'
            $('.wish-list').append(list);
          }
        }
      })
    }
  })

  //partner移动
  var partner = sessionStorage.getItem('name');
  if(partner == 'leke'){
    var countNum = setInterval(move,2000);
    var count = 0;
    function move() {
      count ++;
      if(count % 3 == 1){
        $('.bula').addClass('move');
        $('.qiyu').removeClass('move');
      }else if(count % 3 ==2){
        $('.daibo').addClass('move');
        $('.bula').removeClass('move');
      }else if(count % 3 == 0){
        $('.qiyu').addClass('move');
        $('.daibo').removeClass('move');
      }
    }
  }else if(partner == 'bula'){
    $('.daibo,.qiyu').hide();
    $('.bula').css('left','40vw').addClass('move');
  }else if(partner == 'daibo'){
    $('.bula,.qiyu').hide();
    $('.daibo').css('left','40vw').addClass('move');
  }else if(partner == 'qiyu'){
    $('.daibo,.bula').hide();
    $('.qiyu').css('left','40vw').addClass('move');
  }

  //下载app
  $('.download-btn').on('click',function () {
    var isApp = sessionStorage.getItem('isApp');
    if(isApp == 'false'){
      window.location.href='http://a.app.qq.com/o/simple.jsp?pkgname=com.lalocal.lalocal';
    }else{
      window.location.href='lalocal://app?{"targetType": "2","targetId": "33705"}';
    }
  })

  //跳转到partner
  $('.bula').on('click',function () {
    window.location.href="http://t.cn/RI7fb5O";
  })

  $('.daibo').on('click',function () {
    window.location.href="http://weixin.parkmecn.com/m/6/mobile/coupon/index.html?x=YCWY1614&from=singlemessage&isappinstalled=0";
  })

  $('.qiyu').on('click',function () {
    window.location.href="https://at.umeng.com/XTbSLj";
  })
})
